//
//  NetworkTools.swift
//  WeiBo
//
//  Created by 江潘 on 15/6/27.
//  Copyright © 2015年 江潘. All rights reserved.
//

import UIKit
import AFNetworking


class NetworkTools: AFHTTPSessionManager {
    
    // let、var是线程安全的
    private static let tools:NetworkTools = {
        
        let urlStr = "https://api.weibo.com/"
        
        let url = NSURL(string: urlStr)
        
        let tools = NetworkTools(baseURL: url)
        
        /** AFN json解析器原本支持的解析类型为:"application/json", "text/json", "text/javascript"
            新浪微博获取令牌接口返回的response页面的content-type 为“text/plain”所以要将该类型加入到AFNJSON解析器的acceptableContentTypes中
        */
        tools.responseSerializer.acceptableContentTypes = NSSet(objects:"application/json", "text/json", "text/javascript","text/plain") as Set<NSObject>
        
        return tools
    }()
    
   // 类方法
   class func sharedNewworkTools()->NetworkTools{
    
        return tools
    }
}
